// 患者列表
<template>
  <div>
    <TopManu :thatF="this" :signOut="true" @handleQuit="$router.go(-1)" @handcreate="handcreate"></TopManu>
    <el-row>
      <el-col :span="24" style="margin: 20px 0; text-align: right; padding: 0 20px" class="demo-form-inline">
        <el-form :inline="true" :model="Inquire" label-width="auto" style="text-align: left">
          <el-form-item label="姓名">
            <el-input v-model="Inquire.keyword" placeholder="姓名"></el-input>
          </el-form-item>
          <el-form-item label="年份:">
            <el-date-picker v-model="Inquire.year" type="year" format="yyyy" value-format="yyyy" placeholder="请选择年份">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="创建时间">
            <el-date-picker v-model="Inquire.created_at" type="datetimerange" :picker-options="pickerOptions"
              range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" align="right">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="状态">
            <el-radio-group v-model="Inquire.status">
              <el-radio label="">全部</el-radio>
              <el-radio :label="1">待审核</el-radio>
              <el-radio :label="2">正常</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="
              () => {
                (page = 1), (tableData = []), getMemberIndex();
              }
            ">查询</el-button>
          </el-form-item>
          <!-- <el-form-item>
            <el-button type="primary" @click="()=>{page = 1,Object.keys(Inquire).forEach(key=>{Inquire[key] = '',tabData = [],getMemberIndex()})}">重置</el-button>
          </el-form-item> -->
          <el-form-item style="marginleft: auto">
            <el-button type="primary" @click="
              () => {
                (listFlag = true), (listType = 2);
              }
            ">新增患者</el-button>
          </el-form-item>
          <el-form-item style="marginleft: auto">
            <el-button type="primary" @click="addCanLian">新增残联</el-button>
          </el-form-item>
          <el-form-item style="marginleft: auto">
            <el-button type="primary" @click="operate('stop')">停止残联</el-button>
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :span="24" class="fromFlex">
        <FromList :typeCheckbox="true" @handleEdit="handleEdit" @handleSwitchChange="handleSwitchChange"
          :tableTitle="tableTitle" :tableData="tableData" @handelChange="handelChange" />
        <!-- <el-col :span="20" style="marginTop:20px auto;"> -->
        <el-pagination background style="margintop: 20px" :current-page="page" :page-size="limit"
          layout="total , prev, pager, next , jumper" @current-change="handlePagination" :total="userCount">
        </el-pagination>
        <!-- </el-col> -->
      </el-col>

      <el-dialog :title="
        listType == 1
          ? '查看患者信息'
          : listType == 2
            ? '添加患者信息'
            : '编辑患者信息'
      " :visible.sync="listFlag" width="90%" :before-close="handleClose">
        <span>
          <el-col :span="24">
            <el-form :inline="false" :model="listUser" label-width="110px" style="text-align: left">
              <el-col :span="24" style="font-size: 24px; margin: 0px 0 10px 0">
                基本信息
              </el-col>
              <el-col :span="24">
                <el-col :span="6">
                  <el-form-item label="姓名:">
                    <el-input v-model="listUser.name" placeholder="请输入姓名" :disabled="listType == 1"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="身份证号码:">
                    <el-input v-model="listUser.id_card" :disabled="listType == 1" placeholder="请输入身份证号码"
                      @blur="getInfo2(listUser.id_card)"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="出生日期:">
                    <el-date-picker style="width: 100%" v-model="listUser.birthday" type="date"
                      :disabled="listType == 1" placeholder="选择生日">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="性别:">
                    <el-select style="width: 100%" :disabled="listType == 1" v-model="listUser.gender"
                      placeholder="请选择性别">
                      <el-option v-for="item in sex" :key="item.value" :label="item.label" :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="年龄:">
                    <el-input v-model="listUser.age" :disabled="listType == 1" placeholder="请输入年龄"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="婚姻状况:">
                    <el-select style="width: 100%" v-model="listUser.marriage" :disabled="listType == 1"
                      placeholder="请选择婚姻状况">
                      <el-option v-for="item in marriage" :key="item.value" :label="item.label" :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-col>
              <el-col :span="24">
                <el-col :span="6">
                  <el-form-item label="血型:">
                    <el-select style="width: 100%" v-model="listUser.blood_type" :disabled="listType == 1"
                      placeholder="请选择婚姻状况">
                      <el-option v-for="item in blood_type" :key="item.value" :label="item.label" :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="国籍:">
                    <el-select v-model="listUser.country" :disabled="listType == 1" style="width: 100%" filterable
                      placeholder="请输入可搜索国家">
                      <el-option v-for="item in country" :key="item.value" :label="item.name" :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="病人性质:">
                    <el-select style="width: 100%" :disabled="listType == 1" v-model="listUser.nature"
                      placeholder="请选择病人性质">
                      <el-option v-for="item in nature" :key="item.id" :label="item.name" :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-col>
              <el-col :span="24">
                <el-col :span="6">
                  <el-form-item label="民族:">
                    <el-select style="width: 100%" :disabled="listType == 1" v-model="listUser.nation" filterable
                      placeholder="请选择民族">
                      <el-option v-for="item in nation" :key="item.value" :label="item.name" :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="媒介来源:">
                    <el-select style="width: 100%" :disabled="listType == 1" v-model="listUser.source" filterable
                      placeholder="请选择媒介来源">
                      <el-option v-for="item in source" :key="item.id" :label="item.name" :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-col>
              <el-col :span="24" style="font-size: 24px; margin: 0px 0 10px 0">
                补充信息
              </el-col>
              <el-col :span="24">
                <el-col :span="6">
                  <el-form-item label="籍贯:">
                    <el-input v-model="listUser.native_place" :disabled="listType == 1" placeholder="请输入籍贯"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="移动电话:">
                    <el-input v-model="listUser.phone" :disabled="listType == 1" placeholder="请输入移动电话"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="紧急联系电话:">
                    <el-input v-model="listUser.fast_phone" :disabled="listType == 1" placeholder="请输入紧急联系电话">
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="户籍地址:">
                    <el-input v-model="listUser.home_address" :disabled="listType == 1" placeholder="请输入户籍地址">
                    </el-input>
                  </el-form-item>
                </el-col>
              </el-col>
              <el-col :span="24">
                <el-col :span="6">
                  <el-form-item label="职业:">
                    <el-select style="width: 100%" :disabled="listType == 1" v-model="listUser.post"
                      placeholder="请选择职业">
                      <el-option v-for="item in post" :key="item.value" :label="item.name" :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="工作单位:">
                    <el-input v-model="listUser.company" :disabled="listType == 1" placeholder="请输入工作单位"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="证件类型:">
                    <el-select style="width: 100%" :disabled="listType == 1" v-model="listUser.card_type"
                      placeholder="请选择证件类型">
                      <el-option v-for="item in card_type" :key="item.id" :label="item.name" :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="证件号码:">
                    <el-input v-model="listUser.card_number" :disabled="listType == 1" placeholder="请输入证件号码"></el-input>
                  </el-form-item>
                </el-col>
              </el-col>
              <el-col :span="24">
                <el-col :span="6">
                  <el-form-item label="密级:">
                    <el-select style="width: 100%" :disabled="listType == 1" v-model="listUser.secret_level"
                      placeholder="请选择密级">
                      <el-option v-for="item in secret_level" :key="item.value" :label="item.name" :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="学历:">
                    <el-select style="width: 100%" :disabled="listType == 1" v-model="listUser.edu_level"
                      placeholder="请选择学历">
                      <el-option v-for="item in edu_level" :key="item.id" :label="item.name" :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="生育状态:">
                    <el-select style="width: 100%" :disabled="listType == 1" v-model="listUser.birth_status"
                      placeholder="请选择生育状态">
                      <el-option v-for="item in birth_status" :key="item.value" :label="item.name" :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="保险类型:">
                    <el-select style="width: 100%" :disabled="listType == 1" v-model="listUser.insurance_no"
                      placeholder="请选择保险类型">
                      <el-option v-for="item in insurance_no" :key="item.value" :label="item.name" :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-col>
              <el-col :span="24">
                <el-col :span="6">
                  <el-form-item label="社会保障号:">
                    <el-input v-model="listUser.social_card" :disabled="listType == 1" placeholder="请输入社会保障号">
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="是否异地:">
                    <el-select style="width: 100%" :disabled="listType == 1" v-model="listUser.is_nolocal"
                      placeholder="请选择是否异地">
                      <el-option v-for="item in is_nolocal" :key="item.value" :label="item.name" :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="备注:">
                    <el-input type="textarea" :disabled="listType == 1" v-model="listUser.extra_json"
                      placeholder="请输入备注"></el-input>
                  </el-form-item>
                </el-col>
              </el-col>
              <el-col :span="24">
                <el-form-item label="照片:">
                  <el-upload class="avatar-uploader" :headers="headers" :disabled="listType == 1"
                    :action="http + '/upload/image'" :show-file-list="false" :on-success="handleAvatarSuccess"
                    :before-upload="beforeAvatarUpload">
                    <img v-if="imageUrl" :src="imageUrl" class="avatar" />
                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                  </el-upload>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-col :span="24" v-for="(item, key) in listUser.family" :key="key">
                  <el-col :span="24" style="font-size: 24px; margin: 0px 0 10px 0">
                    家庭成员{{ key + 1 }}
                  </el-col>
                  <el-col :span="24">
                    <el-col :span="7">
                      <el-form-item label="名字:">
                        <el-input v-model="item.name" :disabled="listType == 1" placeholder="请输入家庭成员名字"></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="手机号:">
                        <el-input v-model="item.phone" :disabled="listType == 1" placeholder="请输入家庭成员手机号"></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="家庭成员性别:">
                        <el-select style="width: 100%" :disabled="listType == 1" v-model="item.gender"
                          placeholder="请选择家庭成员性别">
                          <el-option v-for="item in sex" :key="item.value" :label="item.label" :value="item.value">
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                  </el-col>
                  <el-col :span="24">
                    <el-col :span="7">
                      <el-form-item label="家庭成员生日:">
                        <el-date-picker style="width: 100%" :disabled="listType == 1" v-model="item.birthday"
                          type="date" placeholder="选择生日">
                        </el-date-picker>
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="家庭成员关系:">
                        <el-input v-model="item.relation" :disabled="listType == 1" placeholder="请输入家庭成员关系"></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="家庭成员地址:">
                        <el-input v-model="item.address" :disabled="listType == 1" placeholder="请输入家庭成员地址"></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="2" :offset="1">
                      <el-button type="primary" :disabled="listType == 1" @click="handleDeleteFamily(key)">删除成员
                      </el-button>
                    </el-col>
                  </el-col>
                </el-col>
                <el-col :span="24">
                  <el-col :span="6">
                    <el-form-item label="添加家庭成员:">
                      <el-button type="primary" :disabled="listType == 1" @click="handleAddFamily">添加成员</el-button>
                    </el-form-item>
                  </el-col>
                </el-col>
              </el-col>
            </el-form>
          </el-col>
        </span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="listFlag = false">取 消</el-button>
          <el-button type="primary" @click="addSave()">确 定</el-button>
        </span>
      </el-dialog>
      <el-dialog title="详情信息" :visible.sync="listFlag3" width="90%">
        <span>
          <el-col :span="24">
            <el-form :inline="false" :model="canliandata" label-width="110px" style="text-align: left">
              <el-col :span="24" style="font-size: 24px; margin: 0px 0 10px 0">
                基本信息
              </el-col>
              <el-col :span="24">
                <el-col :span="6">
                  <el-form-item label="姓名:">
                    {{ canliandata.member_info.name }}
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="性别:">
                    {{ canliandata.member_info.genderName }}
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="身份证:">
                    {{ canliandata.member_info.id_card }}
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="残疾证号:">
                    {{ canliandata.disabled_number }}
                  </el-form-item>
                </el-col>
              </el-col>

              <el-col :span="6">
                <el-form-item label="疾病诊断:">
                  {{ canliandata.disease }}
                </el-form-item>
              </el-col>
              <!-- <el-col :span="6">
                <el-form-item label="国籍:">
                  <el-select v-model="listUser.country" :disabled="listType == 1" style="width:100%;" filterable placeholder="请输入可搜索国家">
                    <el-option
                      v-for="item in country"
                      :key="item.value"
                      :label="item.name"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col> -->
              <el-col :span="6">
                <el-form-item label="户籍地址:">
                  {{ canliandata.member_info.address }}
                </el-form-item>
              </el-col>

              <el-col :span="6">
                <el-form-item label="出生日期:">
                  {{ canliandata.member_info.birthday }}
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="区域:">
                  {{ listUser2.area }}
                </el-form-item>
              </el-col>
              <el-col :span="24" style="font-size: 24px; margin: 0px 0 10px 0">
                陪护
              </el-col>
              <el-col :span="24">
                <el-col :span="6">
                  <el-form-item label="姓名:">
                    {{ canliandata.guarder }}
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="移动电话:">
                    {{ canliandata.link_phone }}
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="关系:">
                    {{ canliandata.guarder_relation }}
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="户籍地址:">
                    {{ canliandata.guarder }}
                  </el-form-item>
                </el-col>
              </el-col>
            </el-form>
          </el-col>
          <el-col :span="24">
            <el-table :data="canliandata.use_record" style="width: 100%">
              <el-table-column prop="created_at" label="日期" width="180">
              </el-table-column>
              <el-table-column prop="amount" label="金额" width="180">
              </el-table-column>
              <el-table-column prop="type" label="类型">
                <template slot-scope="scope">
                  {{ scope.row.type == 1 ? "门诊" : "住院" }}
                </template>
              </el-table-column>
            </el-table>
          </el-col>
        </span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="listFlag3 = false">取 消</el-button>
        </span>
      </el-dialog>
      <el-dialog title="添加残联患者信息" :visible.sync="listFlag2" v-if="listFlag2" width="70%" :before-close="handleClose">
        <span>
          <el-col :span="24" class="box">
            <el-form :inline="false" :model="listUser2" label-width="110px" style="text-align: left">
              <el-col :span="24" style="font-size: 24px; margin: 0px 0 10px 0">
                基本信息
              </el-col>
              <el-col :span="24" class="box_list">
                <el-col :span="6">
                  <el-form-item label="姓名:">
                    <el-popover placement="bottom-end" v-model="visiblePatient" trigger="focus">
                      <el-input placeholder="请输入患者姓名" slot="reference" v-model="patient_name"
                        @input="getMemberIndex2()">
                      </el-input>

                      <el-table v-loading="patientLoading" @current-change="xuanzePatient" height="300" :data="
                        tableData2.filter(
                          (data) =>
                            !patient_name ||
                            data.name
                              .toLowerCase()
                              .includes(patient_name.toLowerCase())
                        )
                      ">
                        <el-table-column type="index" label="序号" width="50">
                        </el-table-column>

                        <el-table-column width="100" property="name" label="姓名"></el-table-column>
                        <el-table-column width="200" property="id_card" label="卡号"></el-table-column>

                        <el-table-column width="150" property="birthday" label="生日"></el-table-column>
                      </el-table>
                    </el-popover>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="残联号:">
                    <el-input v-model="listUser2.disabled_number" placeholder="请输入残联号"></el-input>
                  </el-form-item>
                </el-col>

                <el-col :span="6">
                  <el-form-item label="疾病:">
                    <el-popover placement="bottom-end" width="500px" trigger="focus">
                      <el-input placeholder="选择诊断" slot="reference" v-model="dictname" @input="getgetDiseaseDict()">
                        <i slot="suffix" class="el-input__icon el-icon-search"></i>
                      </el-input>

                      <el-table height="300" @row-click="xuanzeDatathree" :data="disease_list">
                        <el-table-column label="序号" prop="id" width="50">
                        </el-table-column>

                        <el-table-column label="疾病编码" prop="code" width="150">
                        </el-table-column>
                        <el-table-column label="疾病名称" prop="name" width="250">
                        </el-table-column>
                      </el-table>
                      <el-pagination :current-page="page2" :page-size="limit2" @current-change="handlePagination"
                        :total="pageCount2" layout="prev, pager, next">
                      </el-pagination>
                    </el-popover>
                  </el-form-item>
                </el-col>
                <el-col :span="7">
                  <el-form-item label="门诊余额:">
                    <el-input v-model="listUser2.clinic_balance" placeholder="请输入门诊余额"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="7">
                  <el-form-item label="住院余额:">
                    <el-input v-model="listUser2.hosp_balance" placeholder="请输入住院余额"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="年份:">
                    <el-date-picker v-model="listUser2.year" type="year" format="yyyy" value-format="yyyy"
                      placeholder="请选择年份">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="区域:">
                    <!-- <el-cascader
                      size="large"
                      :options="options"
                      v-model="listUser2.cityEcho"
                      @change="handleChange"
                    >
                    </el-cascader> -->
                    <el-select @change="handleChange" v-model="listUser2.cityEcho" placeholder="请选择">
                      <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-col>

              <el-col :span="24">
                <el-col :span="24">
                  <el-col :span="24" style="font-size: 24px; margin: 0px 0 10px 0">
                    监护人
                  </el-col>
                  <el-col :span="24" class="box_list">
                    <el-col :span="7">
                      <el-form-item label="名字:">
                        <el-input v-model="listUser2.guarder" placeholder="请输入监护人名字"></el-input>
                      </el-form-item>
                    </el-col>

                    <el-col :span="7">
                      <el-form-item label="监护人关系:">
                        <el-select v-model="listUser2.guarder_relation" placeholder="监护人关系">
                          <el-option v-for="(item, index) in relation" :key="index" :label="item.label"
                            :value="item.value">{{ item.label }}</el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="监护人手机:">
                        <el-input v-model="listUser2.link_phone" placeholder="监护人手机"></el-input>
                      </el-form-item>
                    </el-col>
                  </el-col>
                </el-col>
              </el-col>
            </el-form>
          </el-col>
        </span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="listFlag2 = false">取 消</el-button>
          <el-button type="primary" @click="addcanlianSave()">确 定</el-button>
        </span>
      </el-dialog>
    </el-row>
  </div>
</template>

<script>
import {
  getMemberIndex,
  addSave,
  getProfileInfo,
  getSetStatus,
  stopCanLian,
} from "@/api/patient";

import { getgetDiseaseDict } from "@/api/register";
import {
  disabled_memberindex,
  disabled_membersave,
  disabled_membercheck,
  disabled_membershow,
} from "@/api/canlian";
import { getCityRegion } from "@/api/dict";
import TopManu from "@/components/TopMenu";
import { Format } from "@/utils/transtionDate";
import FromList from "@/forComponents/fromList/fromList";
import { patientTitle } from "./tableTitle.js";
import { handleDictIndex } from "@/api/organization";
import { http } from "@/utils/server";
import { objectValueAllEmpty } from "@/utils/ifObject";
import { regionData } from "element-china-area-data";
// import {} from ""
let that;
export default {
  name: "Federation",
  data() {
    return {
      options: [],
      topmanuArry: [
        {
          class: "icon-his_60_pandian",
          name: "慢特病",
          key: "1",
        },
      ],
      userCount: 0,
      Inquire: {
        //搜索数据
        keyword: "",
        status: "",
        year: "",
        created_at: [],
      },
      listFlag2: false,
      listFlag3: false,
      dictname: "",
      threeSelectLoading: false,
      visiblePatient: false,
      disease_list: [],
      listUser2: {
        member_id: "",
        disabled_number: "",
        disease: "",
        guarder: "",
        guarder_relation: "",
        link_phone: "",
        clinic_balance: "",
        hosp_balance: "",
        year: "",
        area: "",
        city: "",
        province: "",
        area_code: "",
        city_code: "",
        province_code: "",
        cityEcho: [],
      },
      pickerOptions: {
        //时间快捷选项
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      tableData: [],
      tableData2: [],
      patient_name: "",
      patientLoading: false,
      tableTitle: patientTitle,
      listFlag: false, //弹窗开关
      listType: 2, //1查看,2添加,3编辑
      listUser: {
        name: "", //姓名
        id_card: "", //身份证号
        gender: "", //性别
        age: "", //年龄
        phone: "", //手机号
        birthday: "", //生日
        marriage: "", //婚姻状态   1未知 2未婚 3已婚 4离异 5丧偶
        blood_type: "", //血型  @1 A型 @2 B型 @3 O型 @4 AB型 @5 未知
        rh_blood_type: "", //rh血型 @1阴性 @2 阳性  @3 未知
        country: "CHN", //国家， 字典id 33，这里需要的是字典的name值
        nation: "", //民族 字典id 37，这里需要的是字典的name值
        address: "", // 住址
        social_card: "", //社保卡号
        source: "", //媒介来源 40
        nature: "", //病人性质: 读取数据字典   4 取字典的id 值
        post: "", //职业
        company: "", //所在单位
        email: "", //邮箱
        native_place: "", //籍贯
        zip_code: "", //邮编
        tel: "", //家庭电话
        card_type: "", // 证件类型  : 读取数据字典   25 取字典的id 值
        card_number: "", //证件号码
        secret_level: "", //密级 @1 普通 @2 机密@3 绝密
        home_address: "", //户籍地址
        edu_level: "", //学历  数据字典为 39，取值为name
        birth_status: "", //生育状态 @1 未育 @2 已育
        is_nolocal: "", //是否外地  @1 是  @2 否
        avatar: "", //照片地址
        fast_name: "", //紧急联系人
        fast_phone: "", //联系人手机号
        insurance_no: "", //保险类型
        family: [
          {
            name: "", //家庭成员姓名
            phone: "", //家庭成员手机号
            gender: "", //家庭成员性别
            birthday: "", //家庭成员生日
            relation: "", //家庭成员关系
            address: "", //家庭成员地址
          },
        ],
      },
      sex: [
        {
          value: 1,
          label: "男",
        },
        {
          value: 2,
          label: "女",
        },
      ],
      marriage: [
        {
          value: 1,
          label: "未知",
        },
        {
          value: 2,
          label: "未婚",
        },
        {
          value: 3,
          label: "已婚",
        },
        {
          value: 4,
          label: "离异",
        },
        {
          value: 5,
          label: "丧偶",
        },
      ],
      blood_type: [
        //血型select
        {
          value: 1,
          label: "A型",
        },
        {
          value: 2,
          label: "B型",
        },
        {
          value: 3,
          label: "O型",
        },
        {
          value: "4",
          label: "AB型",
        },
        {
          value: "5",
          label: "未知",
        },
      ],
      rh_blood_type: [
        //RH血型select
        {
          value: 1,
          label: "阴性",
        },
        {
          value: 2,
          label: "阳性",
        },
        {
          value: 3,
          label: "未知",
        },
      ],
      birth_status: [
        //生育状态
        {
          value: 1,
          label: "未育",
        },
        {
          value: 2,
          label: "已育",
        },
      ],
      is_nolocal: [
        //是否外地select
        {
          value: 1,
          label: "是",
        },
        {
          value: 2,
          label: "否",
        },
      ],
      relation: [
        {
          label: "母女",
          value: "1",
        },
        {
          label: "父子",
          value: "2",
        },
        {
          label: "母子",
          value: "3",
        },
        {
          label: "兄弟",
          value: "4",
        },
        {
          label: "姐妹",
          value: "5",
        },
        {
          label: "姐弟",
          value: "10",
        },
        {
          label: "兄妹",
          value: "11",
        },
        {
          label: "朋友",
          value: "6",
        },
        {
          label: "夫妻",
          value: "7",
        },
        {
          label: "父女",
          value: "8",
        },
        {
          label: "其他",
          value: "9",
        },
      ],
      country: [],
      nature: [],
      post: [],
      card_type: [],
      secret_level: [
        {
          value: 1,
          name: "普通",
        },
        {
          value: 2,
          name: "机密",
        },
        {
          value: 3,
          name: "绝密",
        },
      ],
      edu_level: [],
      birth_status: [
        {
          value: 1,
          name: "未育",
        },
        {
          value: 2,
          name: "已育",
        },
      ],
      is_nolocal: [
        {
          value: 1,
          name: "是",
        },
        {
          value: 2,
          name: "否",
        },
      ],
      insurance_no: [],
      nation: [],
      source: [],
      http: http,
      headers: {
        Authorization: "Bearer " + localStorage.getItem("token"),
      },
      imageUrl: "",
      page: 1,
      limit: 10,
      page2: 1,
      limit2: 15,
      pageCount2: 0,
      canliandata: {
        id: "",
        member_id: "",
        disabled_number: "",
        disease: "",
        guarder: "",
        guarder_relation: "",
        link_phone: "",
        check_date: "",
        status: "",
        check_user: "",
        year: "",
        clinic_init_amount: "",
        clinic_total_amount: "",
        clinic_balance: "",
        hosp_init_amount: "",
        hosp_total_amount: "",
        hosp_balance: "",
        created_at: "",
        updated_at: "",
        create_by: "",
        member_info: {
          id: "",
          name: "",
          gender: "",
          age: "",
          id_card: "",
          phone: "",
          address: "",
          birthday: "",
        },

        use_record: [],
      },
      stop_id: [],
    };
  },
  mounted() {
    // console.log("regionData",regionData)
    // console.log("regionData",regionData.find(v=>v.value=="610000"))

    that = this;
    that.getMemberIndex();
    that.getMemberIndex2();
    this.getgetDiseaseDict();
    that.getAll();
    that.getCity();
  },
  methods: {
    addCanLian(){
      this.reSet()
      that.listFlag2 = true;
    },
    getCity() {
      getCityRegion({})
        .then((res) => {
          if (res.code == 200) {
            that.options = res.data;
          }
        })
        .catch((e) => { });
    },
    handelChange(e) {
      console.log("r", e);
      that.stop_id = [];
      e.forEach((v) => {
        that.stop_id.push(v.id);
      });
      console.log(" that.stop_id", that.stop_id);
    },
    operate(e) {
      switch (e) {
        case "stop":
          console.log("that.stop_id", that.stop_id);
          if (!that.stop_id.length) {
            return that.$message({
              message: "请选择需要停止的残联",
              type: "error",
            });
          }
          this.$confirm("确定要停止残联吗？", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
          }).then(() => {
            stopCanLian({ id: that.stop_id.toString() }).then((res) => {
              if (res.code == 200) {
                setTimeout(() => {
                  this.getMemberIndex();
                }, 1000);
              }
              this.$message({
                message: res.message,
                type: "success",
              });
            });
          });
          break;
        default:
          break;
      }
    },
    handleChange(e) {
      this.listUser2 = {
        ...this.listUser2,
        area: that.options.find((v) => v.id == e).name,
        area_code: e,
      };
      // this.options.forEach((v) => {
      //   if (this.listUser2.cityEcho[0] == v.value) {
      //     this.listUser2={
      //       ...this.listUser2,
      //       province:v.label,
      //       province_code:v.value,
      //     }

      //   }

      //   v.children &&
      //     v.children.forEach((v2) => {
      //       if (this.listUser2.cityEcho[1] == v2.value) {

      //         this.listUser2={
      //           ...this.listUser2,
      //           city:v2.label,
      //           city_code:v2.value,
      //         }
      //       }
      //       v2.children &&
      //         v2.children.forEach((v3) => {
      //           if (this.listUser2.cityEcho[2] == v3.value) {

      //              this.listUser2={
      //                 ...this.listUser2,
      //                 area:v3.label,
      //                 area_code:v3.value,
      //               }
      //           }
      //         });
      //     });
      // });
      console.log("this.listUser2", this.listUser2);
    },
    handlePagination(e) {
      this.tabData = [];
      this.page = e;
      this.getMemberIndex();
    },
    handlePagination2(e) {
      this.page2 = e;
      this.getgetDiseaseDict();
    },
    handcreate(item) {
      console.log("123");
      this.$router.push({ name: "chronicIdiopathicDisease" });
    },
    xuanzeDatathree(item) {
      this.listUser2.disease = item.id;
      this.dictname = item.name;
      this.patientLoading = false;
    },
    disabled_membershow(e) {
      disabled_membershow({ id: e }).then((res) => {
        console.log(res);
        this.canliandata = res.data;
        this.canliandata.member_info.genderName =
          res.data.member_info.gender == 1
            ? "男"
            : res.data.member_info.gender == 2
              ? "女"
              : "";
        (this.listUser2 = {
          member_id: res.data.member_id,
          disabled_number: res.data.disabled_number,
          disease: res.data.disease,
          guarder: res.data.guarder,
          guarder_relation: res.data.guarder_relation,
          link_phone: res.data.link_phone,
          clinic_balance: res.data.clinic_balance,
          hosp_balance: res.data.hosp_balance,
          id: res.data.id,
          year: res.data.year.toString(),
          area: res.data.area,
          city: res.data.city,
          province: res.data.province,
          area_code: res.data.area_code,
          city_code: res.data.city_code,
          province_code: res.data.province_code,
          cityEcho:res.data.area_code?parseInt(res.data.area_code):res.data.area_code,
          
        }),
          (
            //  this.listUser2=res.data
            (this.patient_name = res.data.member_info.name)
          );
          this.dictname=res.data.disease_name;
      });
    },
    getProfileInfo(e) {
      getProfileInfo({ id_card: e })
        .then((res) => {
          res.data.family = res.data.get_family;
          that.getAll();
          res.data.edu_level = parseFloat(res.data.edu_level);
          that.listUser = res.data;
        })
        .catch((e) => {
          that.$message({
            message: e.message,
            type: "error",
          });
        });
    },
    // 操作按钮
    handleEdit(e) {
      console.log(e);
      if (e.key == 1) {
        that.disabled_membershow(e.data.id);
        that.listFlag3 = true;
        that.listType = 1;
      } else if (e.key == 3) {
        that.disabled_membershow(e.data.id);
        that.listFlag2 = true;
        // that.listType = 2;
      } else if (e.key == 2) {
        //  that.getProfileInfo(e.data.)
        //  that.listFlag = true
        //  that.listType = 3
        this.$confirm("是否通过审核", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
        }).then(() => {
          disabled_membercheck({ id: e.data.id }).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: "审核成功",
                type: "success",
              });
              this.getMemberIndex();
            } else {
              //  this.$message(res.message);
            }
          });
        });
      } else if (e.key == 4) {
        this.$confirm("确定要停止残联吗？", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
        }).then(() => {
          stopCanLian({ id: e.data.id.toString() }).then((res) => {
            if (res.code == 200) {
              setTimeout(() => {
                this.getMemberIndex();
              }, 1000);
            }
            this.$message({
              message: res.message,
              type: "success",
            });
          });
        });
      }
    },
    getInfo2(idCard) {
      let sex = null;
      let birth = null;
      let myDate = new Date();
      let month = myDate.getMonth() + 1;
      let day = myDate.getDate();
      let age = 0;

      if (idCard.length === 18) {
        age = myDate.getFullYear() - idCard.substring(6, 10) - 1;
        sex = idCard.substring(16, 17);
        birth =
          idCard.substring(6, 10) +
          "-" +
          idCard.substring(10, 12) +
          "-" +
          idCard.substring(12, 14);
        if (
          idCard.substring(10, 12) < month ||
          (idCard.substring(10, 12) === month &&
            idCard.substring(12, 14) <= day)
        )
          age++;
      }
      if (idCard.length === 15) {
        age = myDate.getFullYear() - idCard.substring(6, 8) - 1901;
        sex = idCard.substring(13, 14);
        birth =
          "19" +
          idCard.substring(6, 8) +
          "-" +
          idCard.substring(8, 10) +
          "-" +
          idCard.substring(10, 12);
        if (
          idCard.substring(8, 10) < month ||
          (idCard.substring(8, 10) === month && idCard.substring(10, 12) <= day)
        )
          age++;
      }

      if (sex % 2 === 0) sex = 0;
      // 性别代码 1代表男，0代表女，暂时不涉及其他类型性别
      else sex = 1;
      this.listUser.gender = sex;
      this.listUser.birthday = birth;
      this.listUser.age = age;
    },
    // 状态操作
    handleSwitchChange(data) {
      let { data: list } = data;
      that.getSetStatus(list.id, list.flag ? 1 : 2);
    },
    //修改账户状态
    getSetStatus(e, q) {
      getSetStatus({ id: e, status: q })
        .then((res) => {
          this.$message({
            message: "修改状态成功",
            type: "success",
          });
          that.tableData = [];
          that.getMemberIndex();
        })
        .catch((e) => {
          this.$message({
            message: e.message,
            type: "error",
          });
        });
    },
    //  删除家庭成员
    handleDeleteFamily(key) {
      that.listUser.family.splice(key, 1);
    },
    handleAddFamily() {
      that.listUser.family.push({
        name: "", //家庭成员姓名
        phone: "", //家庭成员手机号
        gender: "", //家庭成员性别
        birthday: "", //家庭成员生日
        relation: "", //家庭成员关系
        address: "", //家庭成员地址
      });
    },
    getgetDiseaseDict(e) {
      getgetDiseaseDict({
        page: this.page2,
        limit: this.limit2,
        keyword: this.dictname,
      })
        .then((res) => {
          let data = res.data.lists;
          console.log(res);
          this.pageCount2 = res.data.count;
          this.disease_list = data;
        })
        .catch((e) => { });
    },
    addSave() {
      let data = {
        name: "",
        id_card: "",
        gender: "",
      };
      let list = {};
      Object.keys(data).forEach((key) => {
        data[key] = that.listUser[key];
      });
      Object.keys(that.listUser).forEach((item, key) => {
        if (item != "get_family") {
          list[item] = that.listUser[item];
        }
      });
      that.listUser = list;
      if (!objectValueAllEmpty(data)) {
        this.$message({
          message: "请认真填写表单信息",
          type: "error",
        });
        return false;
      }
      addSave({ ...that.listUser })
        .then((res) => {
          that.$message({
            message: res.message,
            type: "success",
          });
          that.listUser = that.$options.data.call(this).listUser;
          that.listFlag = false;
          that.getMemberIndex();
        })
        .catch((e) => {
          that.$message({
            message: e.message,
            type: "error",
          });
        });
    },
    //  关闭弹窗
    handleClose() {
      that.listFlag = false;
      this.listFlag2 = false;
      this.listUser2 = {
        member_id: "",
        disabled_number: "",
        disease: "",
        guarder: "",
        guarder_relation: "",
        link_phone: "",
        clinic_balance: "",
        hosp_balance: "",
        year: "",
        area: "",
        city: "",
        province: "",
        area_code: "",
        city_code: "",
        province_code: "",
        cityEcho: [],
      };
      this.patient_name = "";
    },
    //  获取数据字典
    getAll() {
      that.handleDictIndex("33,4,22,25,39,13,37,40");
    },
    //  获取数据字典
    handleDictIndex(e) {
      handleDictIndex({ group_id: e })
        .then((res) => {
          console.log(res);
          if (res.data.length != 0) {
            res.data.forEach((item) => {
              switch (item.id) {
                case 4:
                  that.nature = item.items;
                  break;
                case 33:
                  that.country = item.items;
                  break;
                case 22:
                  that.post = item.items;
                  break;
                case 25:
                  that.card_type = item.items;
                  break;
                case 39:
                  that.edu_level = item.items;
                  break;
                case 13:
                  that.insurance_no = item.items;
                  break;
                case 37:
                  that.nation = item.items;
                  break;
                case 40:
                  that.source = item.items;
                  break;
              }
            });
          }
        })
        .catch((e) => {
          this.$message({
            message: e.message,
            type: "error",
          });
        });
    },
    handleAvatarSuccess(res, file) {
      that.imageUrl = URL.createObjectURL(file.raw);
      that.listUser.avatar = res.data.url;
    },
    //限制图片
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isJPG && isLt2M;
    },
    getMemberIndex2() {
      getMemberIndex({
        keyword: this.patient_name,
        page: this.page,
        limit: this.limit,
      })
        .then((res) => {
          console.log(res, "000");
          if (res.data.list.length != 0) {
            res.data.list.forEach((item, key) => {
              item.key = key + 1;
              item.genderName = item.gender == 1 ? "男" : "女";
              item.status == 1 ? (item.flag = true) : (item.flag = false);
            });
          }
          // this.userCount = res.data.count
          that.tableData2 = res.data.list;
        })
        .catch((e) => {
          this.$message({
            message: e.message,
            type: "error",
          });
        });
    },
    getMemberIndex() {
      let data = JSON.parse(JSON.stringify(this.Inquire));
      if (data.created_at.length != 0) {
        data.created_at =
          Format(new Date(data.created_at[0])) +
          "|" +
          Format(new Date(data.created_at[1]));
      }

      disabled_memberindex({ ...data, page: this.page, limit: this.limit })
        .then((res) => {
          if (res.data.list.length != 0) {
            res.data.list.forEach((item, key) => {
              item.key = key + 1;
              item.genderName = item.member_info.gender == 1 ? "男" : "女";
              item.name = item.member_info.name;
              item.id_card = item.member_info.id_card;
              item.phone = item.member_info.phone;
              item.real_name = item.create_by_info.real_name;
              item.status =
                item.status == 1
                  ? "待审核"
                  : item.status == 2
                    ? "已通过"
                    : item.status == 3
                      ? "已失效"
                      : "";
            });
          }
          this.userCount = res.data.count;
          that.tableData = res.data.list;
          console.log(that.tableData);
        })
        .catch((e) => {
          this.$message({
            message: e.message,
            type: "error",
          });
        });
    },
    xuanzePatient(item) {
      this.listUser2.member_id = item.id;
      this.patient_name = item.name;
      this.patientLoading = false;
    },
    addcanlianSave() {
      var data = this.listUser2;
      data = {
        ...data,
        // dictName:this.dictname,
        // year:this.listUser.year,
        // area:this.listUser.area,
        // city:this.listUser.city,
        // province:this.listUser.province,
        // area_code:this.listUser.area_code,
        // city_code:this.listUser.city_code,
        // province_code:this.listUser.province_code,
      };
      console.log(data);
      disabled_membersave(data).then((res) => {
        if (res.code == 200) {
          this.$message({
            message: "提交成功",
            type: "success",
          });
          this.listFlag2 = false;
          this.listUser2 = {
            member_id: "",
            disabled_number: "",
            disease: "",
            guarder: "",
            guarder_relation: "",
            link_phone: "",
            clinic_balance: "",
            hosp_balance: "",
            year: "",
            area: "",
            city: "",
            province: "",
            area_code: "",
            city_code: "",
            province_code: "",
            cityEcho: [],
          };
          this.patient_name = "";
          this.dictname = "";

          that.getMemberIndex();
        } else {
          this.$message({
            message: res.message,
            // type: "info",
          });
        }
        console.log(res);
      });
    },
    reSet(){
      this.dictname='';
      this.listUser2= {
        member_id: "",
        disabled_number: "",
        disease: "",
        guarder: "",
        guarder_relation: "",
        link_phone: "",
        clinic_balance: "",
        hosp_balance: "",
        year: "",
        area: "",
        city: "",
        province: "",
        area_code: "",
        city_code: "",
        province_code: "",
        cityEcho: [],
      }
    },
  },
  components: {
    TopManu,
    FromList,
  },
};
</script>

<style lang='scss' scoped>
@import "./index.scss";

.box {
  .box_list {
    display: flex;
    flex-wrap: wrap;

    >div {
      margin-bottom: 20px;
      width: 33%;
    }
  }
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
  border: 1px dashed #d9d9d9;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
}

/deep/ .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 100% !important;
}

.el-select {
  width: 100% !important;
}
</style>
